package cn.lu.joke.net;

import cn.lu.joke.mvp.model.Callback;
import cn.lu.joke.util.LogUtils;
import retrofit2.Call;
import retrofit2.Response;

public class CallBack<T> implements retrofit2.Callback<T> {

    private Callback<T> mModeCallback;

    public CallBack(Callback<T> callback) {
        if (callback == null) {
            throw new IllegalArgumentException("This callback is not null");
        }
        this.mModeCallback  = callback;
    }

    @Override
    public void onResponse(Call<T> call, Response<T> response) {
        if (response.body() != null) {
            mModeCallback.onSuccess(response.body());
        }
        mModeCallback.onComplete();
    }

    @Override
    public void onFailure(Call<T> call, Throwable t) {
        mModeCallback.onError(t);
        mModeCallback.onComplete();
    }
}
